# Load an RDF file into local sesame server
#import os
#import sys
#from optparse import OptionParser
#from httplib import BadStatusLine
from rdflib.graph import ConjunctiveGraph
from semprog import pysesame
__version__ = "$Id$"

def loadGraph2Server(g,url,fname=None):
    data = g.serialize(format='xml')
    c = pysesame.connection(url)
    c.use_repository('3account')
    c.putdata(data,context=fname)

def loadFile2Server(fname,url,format,context=None):
    g = ConjunctiveGraph()
    if isinstance(fname,str):
        fp = open(fname)
        if not context:
            context = os.path.basename(fname)
    else:
        fp=fname
    g.parse(fp,format=format,publicID=context)
    loadGraph2Server(g,url,"<file://%s>"%context)
